<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" ref="elFormRef" label-position="right" :rules="rule" label-width="80px">
        <el-form-item label="尺码:" prop="sizeNum">
          <el-input v-model="formData.sizeNum" :clearable="true"  placeholder="请输入尺码" />
       </el-form-item>
        <el-form-item label="显示顺序:" prop="listOrder">
          <el-input v-model.number="formData.listOrder" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="款式编号:" prop="styleNum">
          <el-input v-model="formData.styleNum" :clearable="true"  placeholder="请输入款式编号" />
       </el-form-item>
        <el-form-item label="配件名称:" prop="accessoryName">
          <el-input v-model="formData.accessoryName" :clearable="true"  placeholder="请输入配件名称" />
       </el-form-item>
        <el-form-item label="自购_外购:" prop="orderType">
          <el-input v-model="formData.orderType" :clearable="true"  placeholder="请输入自购_外购" />
       </el-form-item>
        <el-form-item label="颜色编号:" prop="colorNum">
          <el-input v-model="formData.colorNum" :clearable="true"  placeholder="请输入颜色编号" />
       </el-form-item>
        <el-form-item label="SAP物料说明:" prop="sapDesc">
          <el-input v-model="formData.sapDesc" :clearable="true"  placeholder="请输入SAP物料说明" />
       </el-form-item>
        <el-form-item label="外观规格:" prop="appearanceSpec">
          <el-input v-model="formData.appearanceSpec" :clearable="true"  placeholder="请输入外观规格" />
       </el-form-item>
        <el-form-item label="数量:" prop="num">
          <el-input v-model="formData.num" :clearable="true"  placeholder="请输入数量" />
       </el-form-item>
        <el-form-item label="单位:" prop="unit">
          <el-input v-model="formData.unit" :clearable="true"  placeholder="请输入单位" />
       </el-form-item>
        <el-form-item label="物料群组:" prop="group">
          <el-input v-model="formData.group" :clearable="true"  placeholder="请输入物料群组" />
       </el-form-item>
        <el-form-item label="备注:" prop="note">
          <el-input v-model="formData.note" :clearable="true"  placeholder="请输入备注" />
       </el-form-item>
        <el-form-item label="元件编号:" prop="componentNum">
          <el-input v-model="formData.componentNum" :clearable="true"  placeholder="请输入元件编号" />
       </el-form-item>
        <el-form-item label="配件群组:" prop="accessoryGroup">
          <el-input v-model="formData.accessoryGroup" :clearable="true"  placeholder="请输入配件群组" />
       </el-form-item>
        <el-form-item label="创建者:" prop="createdBy">
          <el-input v-model.number="formData.createdBy" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="更新者:" prop="updatedBy">
          <el-input v-model.number="formData.updatedBy" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="删除者:" prop="deletedBy">
          <el-input v-model.number="formData.deletedBy" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="父节点id:" prop="parentId">
          <el-input v-model="formData.parentId" :clearable="true"  placeholder="请输入父节点id" />
       </el-form-item>
        <el-form-item label="层级:" prop="level">
          <el-input v-model="formData.level" :clearable="true"  placeholder="请输入层级" />
       </el-form-item>
        <el-form-item label="斋架/配件:" prop="accessoryType">
          <el-input v-model="formData.accessoryType" :clearable="true"  placeholder="请输入斋架/配件" />
       </el-form-item>
        <el-form-item label="Lct:" prop="lct">
          <el-input v-model="formData.lct" :clearable="true"  placeholder="请输入Lct" />
       </el-form-item>
        <el-form-item label="标准说明:" prop="standardDesc">
          <el-input v-model="formData.standardDesc" :clearable="true"  placeholder="请输入标准说明" />
       </el-form-item>
        <el-form-item label="排序字串:" prop="sortLetter">
          <el-input v-model="formData.sortLetter" :clearable="true"  placeholder="请输入排序字串" />
       </el-form-item>
        <el-form-item label="策略群组:" prop="strategyGroup">
          <el-input v-model="formData.strategyGroup" :clearable="true"  placeholder="请输入策略群组" />
       </el-form-item>
        <el-form-item label="物料群组说明/编号:" prop="groupDesc">
          <el-input v-model="formData.groupDesc" :clearable="true"  placeholder="请输入物料群组说明/编号" />
       </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
          <el-button type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import {
  createMasterBOMAccessorySpec,
  updateMasterBOMAccessorySpec,
  findMasterBOMAccessorySpec
} from '@/api/masterBOMAccessorySpec'

defineOptions({
    name: 'MasterBOMAccessorySpecForm'
})

// 自动获取字典
import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref, reactive } from 'vue'

const route = useRoute()
const router = useRouter()

const type = ref('')
const formData = ref({
            sizeNum: '',
            listOrder: 0,
            styleNum: '',
            accessoryName: '',
            orderType: '',
            colorNum: '',
            sapDesc: '',
            appearanceSpec: '',
            num: '',
            unit: '',
            group: '',
            note: '',
            componentNum: '',
            accessoryGroup: '',
            createdBy: 0,
            updatedBy: 0,
            deletedBy: 0,
            parentId: '',
            level: '',
            accessoryType: '',
            lct: '',
            standardDesc: '',
            sortLetter: '',
            strategyGroup: '',
            groupDesc: '',
        })
// 验证规则
const rule = reactive({
})

const elFormRef = ref()

// 初始化方法
const init = async () => {
 // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (route.query.id) {
      const res = await findMasterBOMAccessorySpec({ ID: route.query.id })
      if (res.code === 0) {
        formData.value = res.data.remasterBOMAccessorySpec
        type.value = 'update'
      }
    } else {
      type.value = 'create'
    }
}

init()
// 保存按钮
const save = async() => {
      elFormRef.value?.validate( async (valid) => {
         if (!valid) return
            let res
           switch (type.value) {
             case 'create':
               res = await createMasterBOMAccessorySpec(formData.value)
               break
             case 'update':
               res = await updateMasterBOMAccessorySpec(formData.value)
               break
             default:
               res = await createMasterBOMAccessorySpec(formData.value)
               break
           }
           if (res.code === 0) {
             ElMessage({
               type: 'success',
               message: '创建/更改成功'
             })
           }
       })
}

// 返回按钮
const back = () => {
    router.go(-1)
}

</script>

<style>
</style>
